import React, {useEffect, useState} from 'react';
import {createStackNavigator, } from '@react-navigation/stack';
import router from './tabs';
import AsyncStorage from '@react-native-community/async-storage';
import Login from '../pages/Login'
const Stack = createStackNavigator();

const StackNavigator = () => {
  const [isSignIn, setIsSignIn] = useState(false)
  // 判断是否登录
  useEffect(() => {
    checkIsSignIn()
  }, [])
  const checkIsSignIn = async () => {
    const token = await AsyncStorage.getItem('token')
    if(token){
      setIsSignIn(true)
    }
  }
  return (
    <Stack.Navigator screenOptions={{headerShown: false}}>
      {
        !isSignIn ?  
        <Stack.Screen name="Login" component={Login}></Stack.Screen>:
        <></>
      }
      {router.map((item, index) => {
        return (
          <Stack.Screen
            name={item.name}
            component={item.component}
            key={item.name}></Stack.Screen>
        );
      })}
    </Stack.Navigator>
  );
};
export default StackNavigator;
 